package com.decent.ejfadmin.common.bean;

import java.text.DecimalFormat;
import java.util.List;

/**
 * 分页实体
 *
 * @param <T>
 * @author 王健旭
 */
@SuppressWarnings({"serial", "unused"})
public class Page<T> implements java.io.Serializable {
    /**
     * 当前页
     */
    private Integer page = 1;
    /**
     * 最大页/总页数
     */
    private Integer maxPage;
    /**
     * 每页长度
     */
    private Integer size = 10;
    /**
     * 总记录
     */
    private Integer total = 0;
    /**
     * 查询条件
     */
    private T queryBean;
    /**
     * 结果集
     */
    private List<T> resultList;

    public Page() {
    }

    public Page(Integer page, Integer size) {
        this.page = page;
        this.size = size;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public List<T> getResultList() {
        return resultList;
    }

    public void setResultList(List<T> resultList) {
        this.resultList = resultList;
    }

    public Integer getMaxPage() {
        return maxPage;
    }

    public void setMaxPage(Integer maxPage) {
        this.maxPage = maxPage;

    }

    public T getQueryBean() {
        return queryBean;
    }

    public void setQueryBean(T queryBean) {
        this.queryBean = queryBean;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
        this.maxPage = Integer.parseInt(new DecimalFormat("#0").format(Math
                .ceil(total / 1.0 / size)));
        this.total = total;
    }

    /**
     * 获取当前分页开始坐标
     *
     * @return 起始行数
     */
    public Integer getBeginIndex() {
        return ((this.page - 1) * this.size);
    }

    /**
     * 获取当前分页结束坐标
     *
     * @return 终止行数
     */
    public Integer getEndIndex() {
        return this.page * this.size;
    }

}
